-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Workspace]Fix error toasts in sample data page #8842
base: main
Are you sure you want to change the base?
[Workspace]Fix error toasts in sample data page #8842
Conversation
Signed-off-by: Lin Wang <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8842 +/- ##
==========================================
+ Coverage 60.88% 60.90% +0.02%
==========================================
Files 3802 3802
Lines 91083 91114 +31
Branches 14383 14391 +8
==========================================
+ Hits 55455 55496 +41
+ Misses 32086 32074 -12
- Partials 3542 3544 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
This reverts commit b92b333. Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: Lin Wang <[email protected]>
@@ -41,11 +41,16 @@ export async function listSampleDataSets(dataSourceId) { | |||
return await getServices().http.get(sampleDataUrl, { query }); | |||
} | |||
|
|||
const isWorkspaceEnabled = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking if it is workspaceEnabled or permissionControlEnabled.
@@ -144,6 +148,59 @@ export class WorkspaceUiSettingsClientWrapper { | |||
return wrapperOptions.client.update(type, id, attributes, options); | |||
}; | |||
|
|||
const deleteUiSettingsWithWorkspace = async ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const deleteUiSettingsWithWorkspace = async ( | |
const deleteWithDefaultIndexPatternCheck = async ( |
export async function installSampleDataSet(id, sampleDataDefaultIndex, dataSourceId) { | ||
const query = buildQuery(dataSourceId); | ||
await getServices().http.post(`${sampleDataUrl}/${id}`, { query }); | ||
|
||
if (getServices().uiSettings.isDefault('defaultIndex')) { | ||
if (!isWorkspaceEnabled() && getServices().uiSettings.isDefault('defaultIndex')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a unit test to cover this condition check?
if ( | ||
!isWorkspaceEnabled() && | ||
!uiSettings.isDefault('defaultIndex') && | ||
uiSettings.get('defaultIndex') === sampleDataDefaultIndex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a comment here, workspace_ui_settings_client_wrapper will handle default index pattern reset?
const defaultIndexPatternWorkspaces = workspaceObjects.saved_objects.filter( | ||
({ attributes }) => attributes?.uiSettings?.[DEFAULT_INDEX_PATTERN_UI_SETTINGS_ID] === id | ||
); | ||
try { | ||
await this.getWorkspaceTypeEnabledClient(wrapperOptions.request).bulkUpdate( | ||
defaultIndexPatternWorkspaces.map((savedObject) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we check defaultIndexPatternWorkspaces is not empty first?
also will bulkUpdate an empty list throw errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bulkUpdate
won't throw errors for empty list. But you're right, we can add a empty check logic for it.
Signed-off-by: Lin Wang <[email protected]>
* This is necessary because default index patterns cannot be deleted | ||
* when a workspace is enabled and the user lacks the required permissions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is necessary because default index patterns cannot be deleted
when a workspace is enabled and the user lacks the required permissions.
I might miss something here, do we have special check on index pattern when deleting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR, we will delete index patterns of sample data first when user want to uninstall sample data. So there are different cases when user try to uninstall sample data.
- Case 1: Index pattern is default index pattern and user is
dashboards admin
orworkspace admin
, Index pattern can be removed - Case 2: Index pattern is default index pattern and user is
workspace read and write
andworkspace read only
, index pattern can't be removed - Case 3: Index pattern is not default index pattern and user is
dashboards admin
,workspace admin
orworkspace read & write
, index pattern can be removed - Case 4: Index pattern is not default index pattern and user is
workspace read only
, index pattern can't be removed
This PR will enhance case 1 and case 2, will try to remove ui settings first when deleted index patterns are default index pattern.
@@ -144,6 +148,61 @@ export class WorkspaceUiSettingsClientWrapper { | |||
return wrapperOptions.client.update(type, id, attributes, options); | |||
}; | |||
|
|||
const deleteWithDefaultIndexPatternCheck = async ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit concern that we're over complicating this saved object wrapper, it's intended to be a wrapper for config
type of object, but now we're doing an implicit cascading updating when a index-pattern
is deleted.
Could you please elaborate why this change is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, we can keep the default index pattern validation logic in the ui setting PR when trying to delete index patterns. Then it will throw an error if a user tries to remove a default index pattern. The benefits of leaving the cascading updating logic were that the user doesn't need to call the UI setting separately. I'm open to this. After this change, the user will get an error when trying to uninstall sample data and the index pattern is a default index pattern. Do you think if we should remove the default index patterns ui setting before sample data uninstall?
Description
This PR addresses the issue of error toasts appearing on the sample data page when installing or uninstalling sample data. The root cause was that the user did not have permission to update UI settings at the workspace level. The changes in this PR include:
Screenshot
No UI Changes
Testing the changes
yarn osd bootstrap --single-version loose
.config/opensearch_dashboards.yml
:yarn start --no-base-path
.Changelog
Check List
yarn test:jest
yarn test:jest_integration